#!/usr/bin/python3.4
# -*- coding: utf-8 -*-

import sys
import copy

OK = 0
PE = 4
WA = 5
CF = 6


fin = open(sys.argv[1], "r")
#fin=open("test3.txt","r")
ans = fin.readlines()


fin.close()



s=[4,9,6,1,5,3,2,7,8]
correct=[1,2,3,4,5,6,7,8,9]
i = 0
er=0

while i < len(ans):
    ans[i] = ans[i].replace("\n", "")
    ans[i] = ans[i].replace(" ", "")

    if len(ans[i])==0:
        er=1
    elif ans[i]=="1":
        s[0],s[1],s[4],s[3]=s[3],s[0],s[1],s[4]
    elif ans[i]=="2":
        s[1],s[2],s[5],s[4]=s[4],s[1],s[2],s[5]
    elif ans[i]=="3":
        s[3],s[4],s[7],s[6]=s[6],s[3],s[4],s[7]
    elif ans[i]=="4":
        s[4],s[5],s[8],s[7]=s[7],s[4],s[5],s[8]
    else:
        er=1
    i=i+1

       
if er==1:
    sys.stderr.write("Invalid char in answer ")
    sys.stdout.write("0")
    sys.exit(PE)        

er=0
for i in range(9):
    if s[i]!=correct[i]:
        er=1

if er==0:
    if len(ans)<=7:
        sys.stderr.write("This is right answer ")
        sys.stdout.write("100")
        sys.exit(OK)
    if len(ans)<=10:
        sys.stderr.write("Sequence is not shortest  ")
        sys.stdout.write("70")
        sys.exit(WA)
    if len(ans)<=15:
        sys.stderr.write("Sequence is not shortest  ")
        sys.stdout.write("50")
        sys.exit(WA)
    sys.stderr.write("Sequence is not shortest  ")
    sys.stdout.write("30")
    sys.exit(WA)

sys.stderr.write("Sequence is wrong ")
sys.stdout.write("0")
sys.exit(WA)
